<?php

class Admin_ProductCategoryController extends Zend_Controller_Action{

    public function init(){
		parent::init();
        $layoutPath = APPLICATION_PATH  . '/templates/admin/default';
        $option = array ('layout' => 'index',
        		'layoutPath' => $layoutPath );
        Zend_Layout::startMvc ($option );
	}
    public function indexAction(){
        $product_category = new Admin_Model_ProductCategory();
        $this->view->product_categorys = $product_category->fetchAll();
    }

    public function addAction(){
        $form = new Admin_Form_ProductCategory();
        $form->submit->setLabel('Thêm Sản Phẩm');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $ten = $form->getValue('ten');
                $mo_ta = $form->getValue('mo_ta');
                $ma_loai_cha = (int)$form->getValue('ma_loai_cha');
                $thu_tu_hien_thi = $form->getValue('thu_tu_hien_thi');
                $productcata = new Admin_Model_ProductCategory();
                $productcata->insert(array('ten'=>$ten, 'mo_ta'=>$mo_ta, 'ma_loai_cha'=>$ma_loai_cha, 'thu_tu_hien_thi'=>$thu_tu_hien_thi));
                $this->_helper->redirector('index');
            } else {
                $form->populate($formData);
            }
        }
    }
}
 
